package io.cucumber.core.runner;

import com.zws.cucumber.snapshot.ZwsSnapshotFacade;
import com.zws.cucumber.util.colorfullog.ZwsColorfulLogger;
import io.cucumber.core.backend.TestCaseState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.function.Supplier;

public class SnapshotTakeStepDefinitionMatch extends PickleStepDefinitionMatch {

    private static final Logger logger = ZwsColorfulLogger.of(LoggerFactory.getLogger(SnapshotTakeStepDefinitionMatch.class));

    private Supplier<ZwsSnapshotFacade> snapshotFacadeSupplier;

    private String snapshotName;

    SnapshotTakeStepDefinitionMatch(Supplier<ZwsSnapshotFacade> snapshotFacadeSupplier, String snapshotName) {
        super(Collections.emptyList(), new NoStepDefinition(), null, null);
        this.snapshotFacadeSupplier = snapshotFacadeSupplier;
        this.snapshotName = snapshotName;
    }

    @Override
    public void runStep(TestCaseState state) throws Throwable {
        logger.debug("take snapshot '{}'", snapshotName);
        snapshotFacadeSupplier.get().takeSnapshot(snapshotName);
    }

    @Override
    public void dryRunStep(TestCaseState state) throws Throwable {

    }

    @Override
    public String getCodeLocation() {
        return null;
    }
}
